package com.wtwd.campus.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author zdl
 * @Description
 * @create 2021-06-15 9:20
 */
@Configuration
@EnableSwagger2
@EnableKnife4j
public class SwaggerConfig implements WebMvcConfigurer {

    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("智慧平台")
                .apiInfo(apiInfo())
                .select()
                //此包路径下的类，才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.wtwd.campus.controller"))
                //加了ApiOperation注解的类，才生成接口文档
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
        //.extensions(openApiExtensionResolver.buildSettingExtensions());
//                .securitySchemes(Collections.singletonList(securityScheme()))
//                .securityContexts(securityContexts());
        //.globalOperationParameters(setHeaderToken());
    }

    @Bean(value = "hxyApi")
    public Docket hxyApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("和校园")
                .apiInfo(apiInfo())
                .select()
                //此包路径下的类，才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.wtwd.campus.hxy.controller"))
                //加了ApiOperation注解的类，才生成接口文档
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
        //.extensions(openApiExtensionResolver.buildSettingExtensions());
//                .securitySchemes(Collections.singletonList(securityScheme()))
//                .securityContexts(securityContexts());
        //.globalOperationParameters(setHeaderToken());
    }

    @Bean(value = "h5ManageApi")
    public Docket H5ManageApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("和校园H5")
                .apiInfo(apiInfo())
                .select()
                //此包路径下的类，才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.wtwd.campus.h5_manager.controller"))
                //加了ApiOperation注解的类，才生成接口文档
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
        //.extensions(openApiExtensionResolver.buildSettingExtensions());
//                .securitySchemes(Collections.singletonList(securityScheme()))
//                .securityContexts(securityContexts());
        //.globalOperationParameters(setHeaderToken());
    }

    @Bean(value = "微信")
    public Docket WxApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("微信")
                .apiInfo(apiInfo())
                .select()
                //此包路径下的类，才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.wtwd.campus.wx.controller"))
                //加了ApiOperation注解的类，才生成接口文档
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
        //.extensions(openApiExtensionResolver.buildSettingExtensions());
//                .securitySchemes(Collections.singletonList(securityScheme()))
//                .securityContexts(securityContexts());
        //.globalOperationParameters(setHeaderToken());
    }

    @Bean(value = "VcomApi")
    public Docket VcomApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("VcomApi")
                .apiInfo(apiInfo())
                .select()
                //此包路径下的类，才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.wtwd.campus.vcom.controller"))
                //加了ApiOperation注解的类，才生成接口文档
                .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();
        //.extensions(openApiExtensionResolver.buildSettingExtensions());
//                .securitySchemes(Collections.singletonList(securityScheme()))
//                .securityContexts(securityContexts());
        //.globalOperationParameters(setHeaderToken());
    }

    /**
     * api文档的详细信息
     *
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                // //大标题
                .title("校园卡 后台服务API接口文档")
                // 版本号
                .version("1.0")
//				.termsOfServiceUrl("NO terms of service")
                // 描述
                .description("后台API接口")
                // 作者
                .contact("云平台团队")
                .license("The Apache License, Version 2.0")
                .licenseUrl("https://doc.xiaominfo.com/knife4j/documentation/get_start.html")
                .build();
    }


}
